//
//  WGPersonalController.m
//  WisdomGardon
//
//  Created by 郭壮 on 16/8/22.
//  Copyright © 2016年 Red Persimmon. All rights reserved.
//

#import "WGPersonalController.h"

typedef NS_ENUM(NSUInteger,WGPersonalOption) {
    WGPersonalOptionProfile,
    WGPersonalOptionMyRelease,
    WGPersonalOptionMySign,
    WGPersonalOptionMyUpload,
};

static const CGFloat kHEIGHT = 200;

@interface WGPersonalController ()

@property (nonatomic,weak) UIImageView *bgImageView;

@property (nonatomic,weak) UIImageView *iconImageView;

@property (nonatomic,weak) UILabel *nameLabel;

@property (nonatomic,weak) UILabel *titleLabel;

@end

@implementation WGPersonalController

-(instancetype)init{
    return [UIStoryboard initialVCWithName:@"Personal"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = ZQColorWithHexString(@"#ececf0");
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    self.tableView.contentInset = UIEdgeInsetsMake(kHEIGHT, 0, 0, 0);

    [self setupHeader];
}

-(void)setupHeader{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -kHEIGHT, kSCREENW, kHEIGHT)];
    imageView.image = [UIImage imageNamed:@"ptu_Park-display"];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.tag = 101;
    [self.tableView addSubview:imageView];
    self.bgImageView = imageView;
    
    CGFloat iconWH = 70;
    UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake((kSCREENW - iconWH) * 0.5, imageView.y + 30, iconWH, iconWH)];
    iconView.contentMode = UIViewContentModeScaleAspectFill;
    iconView.clipsToBounds = YES;
    iconView.layer.cornerRadius = iconWH * 0.5;
    iconView.image = [UIImage imageNamed:@"ptu_Parks-display"];
    iconView.userInteractionEnabled = YES;
    [iconView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickIcon)]];
    [self.tableView addSubview:iconView];
    self.iconImageView = iconView;
    
    UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(iconView.frame) + 6, kSCREENW, 18)];
    nameL.text = @"张超";
    nameL.textColor = [UIColor whiteColor];
    nameL.textAlignment = NSTextAlignmentCenter;
    nameL.font = [UIFont systemFontOfSize:16];
    [self.tableView addSubview:nameL];
    self.nameLabel = nameL;
    
    UILabel *titleL = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(nameL.frame) + 6, kSCREENW, 18)];
    titleL.text = @"园区项目经理";
    titleL.textColor = [UIColor whiteColor];
    titleL.textAlignment = NSTextAlignmentCenter;
    titleL.font = [UIFont systemFontOfSize:14];
    [self.tableView addSubview:titleL];
    self.titleLabel = titleL;
}

-(void)didClickIcon{
    [self performSegueWithIdentifier:@"WGProfile" sender:nil];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case WGPersonalOptionProfile:
                NSLog(@"个人资料");
                break;
            case WGPersonalOptionMyRelease:
                NSLog(@"发布");
                break;
            case WGPersonalOptionMySign:
                NSLog(@"签到");
                break;
            case WGPersonalOptionMyUpload:
                NSLog(@"上传");
                break;
            default:
                break;
        }
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint point = scrollView.contentOffset;
    if (point.y < -kHEIGHT) {
        CGRect rect = [self.tableView viewWithTag:101].frame;
        rect.origin.y = point.y;
        rect.size.height = -point.y;
        [self.tableView viewWithTag:101].frame = rect;
    }
}

@end
